import request from '@/utils/request';
import type { Interface, Role } from '../entity'
import type {R} from '@/modules/common/entity';

const API_URL = '/manager/interface';

export class InterfaceApi {
  // 创建新接口
  async create(inter: Interface): Promise<R<Interface>> {
    return request({
      url: API_URL,
      method: 'post',
      data: inter
    })
  }

  // 根据ID获取接口信息
  async getById(id: number): Promise<R<Interface>> {
    return request({
      url: `${API_URL}/${id}`,
      method: 'get'
    })
  }

  // 更新指定ID的接口信息
  async update(id: number,inter: Interface): Promise<R<Interface>> {
    return request({
      url: `${API_URL}/${id}`,
      method: 'put',
      data: inter
    })
  }

  // 删除指定ID的接口
  async delete(id: number): Promise<R<void>> {
    return request({
      url: `${API_URL}/${id}`,
      method: 'delete'
    })
  }

  // 获取所有接口
  async getAll(): Promise<R<Interface[]>> {
    return request({
      url: `${API_URL}`,
      method: 'get'
    })
  }

  // 获取操作数量
  async count(): Promise<R<number>> {
    return request({
      url: `${API_URL}/count`,
      method: 'get',
    })
  }

  // 分页获取接口
  async page(page: number,size: number): Promise<R<Interface[]>> {
    return request({
      url: `${API_URL}/page`,
      method: 'get',
      params: {page, size}
    })
  }

  // 获取操作的角色
  async roles(interId?: number): Promise<R<Role[]>> {
    return request({
      url: `${API_URL}/roles`,
      method: 'get',
      params: {interId}
    })
  }
}